package com.qin.blog.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Swagger2API文档的配置
 * @author Leisure
 * create 2022 2022/10/12 10:12
 **/
//配置注解交个Spring创建对象
@Configuration
//启动会Swagger2
@EnableSwagger2
public class Swagger2Config {
    //Spring的@Bean注解用于告诉方法，产生一个Bean对象 作用与方法上
    @Bean
    public Docket createRestApi(){
        //新建一个Docket下的Swagger对象
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                //设置哪些包下的类生产api接口文档
                .apis(RequestHandlerSelectors.basePackage("com.qin.blog.controller"))
                .paths(PathSelectors.any())
                .build();
    }
    
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("Blog系统")
                .description("Blog API调试")
                .contact("Blog")
                .version("1.0")
                .build();
    }


}
